﻿@model Isaac.Joy.Identity.Web.DtCms.Models.RoleViewModel
@{
    ViewBag.Title = "添加角色";
    Layout = Url.BundleContent("~/Views/Shared/_Layout.cshtml");
}
<div id="mainform">
    <!--导航栏-->
    <div class="location">
        <a href="@Url.Action("Index")" class="back"><i></i><span>返回列表页</span></a>
        <a class="home"><i></i><span>控制面板</span></a>
        <i class="arrow"></i>
        <a href="@Url.Action("Index")"><span>角色管理</span></a>
        <i class="arrow"></i>
        <span>添加角色</span>
    </div>
    <div class="line10"></div>
    <!--/导航栏-->

    <!--内容-->
    <div class="content-tab-wrap">
        <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected">角色权限</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="tab-content">
        <dl>
            <dt>角色名称</dt>
            <dd>
                <input type="text" id="txtName" class="input normal" datatype="*2-200" sucmsg=" " />
                <span class="Validform_checktip">*角色名称</span>
            </dd>
        </dl>
        <dl>
            <dt>权限设置</dt>
            <dd>
                <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="98%">
                    <thead>
                        <tr>
                            <th width="15%">插件</th>
                            <th style="text-align: left;">权限</th>
                        </tr>
                    </thead>
                    <tbody id="var_box">
                        @foreach (var key in Model.Permissions.Keys)
                        {
                            <tr>
                                <td style="white-space: nowrap; word-break: break-all; overflow: hidden; text-align: center;">@key</td>
                                <td style="white-space: nowrap; word-break: break-all; overflow: hidden;">
                                    <div class="rule-multi-checkbox">
                                        <span id="cblItem">
                                            @foreach (var permission in @Model.Permissions[key])
                                            {
                                                <input id="cblItem_@permission.Id" type="checkbox" name="cblPermission" value="@permission.Id" /><label for="cblItem_@permission.Id">@permission.Name</label>
                                            }
                                        </span>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
        </dl>
    </div>
    <!--/内容-->

    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-list">
            <input type="button" value="提交保存" id="btnSubmit" class="btn" />
        </div>
        <div class="clear"></div>
    </div>
    <!--/工具栏-->
</div>
@section scripts{
    <script type="text/javascript">
        $(function () {
            var mainform = $("#mainform").Validform({ tiptype: dtcmstiptype, showAllError: true });

            $("#btnSubmit").click(function () {
                if (!mainform.check()) return false;

                var pvalue = "";

                $("input[name='cblPermission']").each(function () {
                    if ($(this).prop("checked")) {
                        pvalue = pvalue + $(this).val() + ",";
                    }
                });

                $.ajax({
                    url: '@Url.Action("AjaxAdd")',
                    type: "post",
                    data: "Role.Name=" + $("#txtName").val() +
                        "&RoleValue=" + pvalue +
                        "",
                    processData: false,
                    success: function (response) {
                        var data = JSON.parse(response);
                        errorCode.getMsg(data, function () {
                            if (data.success) {
                                $.dialog.alert('添加成功！', function () {
                                    document.location.reload();
                                }, null, "提示");
                            } else {
                                $.dialog.alert('添加失败！');
                            }
                        }, function (e) {
                            $.dialog.alert(data.msg == '' ? e.msg : data.msg);
                        });
                        return false;
                    }
                });
                return false;
            });
        });
    </script>
}